var POLE_STARTING_Y = 0;
var POLE_HEIGHT = 600;
var BIN_HEIGHT = 100;

var BIN_POINTS = 200;
var ATTEMPT_BONUS_POINTS = 700;

var numberOfBins;
var binNumber;

function Game()
{
     this.score = 0;
     this.level = 1;
     this.attempts = 5;
     this.binHeights = new Array();
        
}
//Reset function that resets all the values back to their original numbers.
Game.prototype.resetGame = function()
{
      this.score = 0;
      this.level = 1;
      this.attempts = 5;
      this.binHeights = new Array();
}
Game.prototype.resetGame = function()
{
	this.score = 0;
	this.level = 1;
	this.attempts = 5;
	this.binHeights = new Array();
}
//Playing field for the level that the user is currently on.
//Afterwards, the game will be drawn onto the canvas.
Game.prototype.setGameLevel = function()
{
    var numberOfBins = this.getNumberOfBins();
    this.binHeights = new Array( numberOfBins );
        
    this.setAttempts( this.getNumberOfAttempts() );
        
    var numberOfIntervals = Math.floor( ( POLE_HEIGHT - BIN_HEIGHT * 2 ) / BIN_HEIGHT );
        
    for( i = 0; i < numberOfBins; i = i + 1 )
         {
             var height = Math.floor( Math.random() * numberOfIntervals ) * BIN_HEIGHT + POLE_STARTING_Y + BIN_HEIGHT;
             this.binHeights[ i ] = height;
         }
}
//Calculates the number of pole lines and bins available on the field at a certain level.
Game.prototype.getNumberOfBins = function ()
{
	//For the first level, there will be 1 satellite.
	if( this.level == 1 )
		{
			return 1;
		}
	//For the second level, there will be 3 satellite.
	else if( this.level == 2 )
		{
			return 3;
		}
	//For the third level, there will be 5 satellites.
	else if( this.level == 3)
		{
			return 5;
		}
	//For the fourth level, there will be 4 satellites.
	else if( this.level == 4 )
		{
			return 4;
		}
	//For the fifth and final level, there will be 2 satellites.
	else if( this.level == 5 )
		{
			return 2;
		}
	else
		{
			return 0;
		}
}

//Calculates the number of attempts to launch the astronaut given for each level.
Game.prototype.getNumberOfAttempts = function()
{
	//For the first level, with only 1 satellite, there will be 5 attempts
	//for practice
	if( this.level == 1 )
		{
			return 4;
		}
	//For the second level, with 3 satellites, there will be 6 attempts
	//to make it a bit more challenging.
	if( this.level == 2 )
		{
			return 5;
		}
	//For the third level, with 5 satellites, there will be 7 attempts
	//to make it more difficult.
	if( this.level == 3 )
		{
			return 6;
		}
	//For the fourth level, with 4 satellites, there will be 5 attempts
	//for more difficulty.
	if( this.level == 4 )
		{
			return 5;
		}
	//For the final level, with only 2 satellites, there will be only 2 attempts
	//because it is the final round to beat the game and it needs to be hard.
	if( this.level == 5 )
		{
			return 3;
		}
}

Game.prototype.checkGameStatus = function()
{
	if( this.attempts == 0 )
		{
			return drawOutcomeCanvas();
		}
	else if( this.level == 6 && binNumber == 0 )
		{
			return drawWinnerCanvas();
		}
}
//Return the score function
Game.prototype.getScore = function()
{
        return this.score;
}
//Sets the score function
Game.prototype.setScore = function( score )
{
        this.score = score;
}
//Return the level function
Game.prototype.getLevel = function()
{
        return this.level;
}
//Sets the level function
Game.prototype.setLevel = function( level )
{
        this.level = level;
}
//Return the number of attempts function
Game.prototype.getAttempts = function()
{
        return this.attempts;
}
//Sets the number of attempts function
Game.prototype.setAttempts = function( attempts )
{
        this.attempts = attempts;
}
//Return the bins heights function
Game.prototype.getBinHeights = function()
{
        return this.binHeights;
}